package icu.cocoon.game.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import icu.cocoon.dao.base.BaseService;
import icu.cocoon.game.entity.Pinyin;
import icu.cocoon.game.mapper.PinyinMapper;
import icu.cocoon.game.service.PinyinService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Cocoon
 * @since 2020-07-07
 */
@Service
@CacheConfig(cacheNames = "pinyin")
public class PinyinServiceImpl extends BaseService<PinyinMapper, Pinyin> implements PinyinService {

  @Override
  public boolean existByPinyinAndTone(String pinyin, Integer tone) {
    LambdaQueryWrapper<Pinyin> wrapper =
        new QueryWrapper<Pinyin>().lambda().eq(Pinyin::getPinyin, pinyin).eq(Pinyin::getTone, tone);
    return getMapper().selectCount(wrapper)>0;
  }

  @Override
  @Cacheable
  public Pinyin getOneByPinyinAndTone(String pinyin, Integer tone) {
    LambdaQueryWrapper<Pinyin> wrapper =
        new QueryWrapper<Pinyin>().lambda().eq(Pinyin::getPinyin, pinyin).eq(Pinyin::getTone, tone);
    return getMapper().selectOne(wrapper);
  }

}
